package com.example.springboot.utils.vo;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * desc:用于计算动态分页数据
 * 
 * @author wangsh
 * @date Jan 15, 2018 10:14:02 AM
 * @param <T>
 */
public class GeneralPageVo<T> {

	// 当前页数
	private int page;
	// 每页显示记录数
	private int rows;

	// 当前总页面数
	private int CurrCount;
	// 当前总记录数
	private int TotalCount;

	// // 计算后的总数
	// private Integer pageSize;
	// // 计算后页数
	// private Integer pageIndex;
	// // 计算后的开始位置
	// private Integer startRow;

	private List<T> rowList = new ArrayList<T>();

	public GeneralPageVo() {
		this.CurrCount = 0;
		this.TotalCount = 0;
	}

	public GeneralPageVo(int page, int rows) {
		this.page = page;
		this.rows = rows;
	}

	public GeneralPageVo(List<T> Rows, int CurrCount, int TotalCount) {
		this.rowList = Rows;
		this.CurrCount = CurrCount;
		this.TotalCount = TotalCount;
	}

	public int getCurrCount() {
		return CurrCount;
	}

	public void setCurrCount(int currCount) {
		CurrCount = currCount;
	}

	public int getTotalCount() {
		return TotalCount;
	}

	public void setTotalCount(int totalCount) {
		TotalCount = totalCount;
	}

	public List<T> getRowList() {
		return rowList;
	}

	public void setRowList(List<T> rowList) {
		this.rowList = rowList;
	}

	public int getRows() {
		return rows;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public Integer getPageSize() {
		int pageSize = rows - this.getCurrCount();
		return pageSize;
	}

	// public void setPageSize(Integer pageSize) {
	// this.pageSize = pageSize;
	// }

	public Integer getStartRow() {
		int pageSize = rows - this.getCurrCount();
		int startRow = (page - 1) * rows;
		if (this.getTotalCount() > 0 && pageSize > 0) {
			int m = this.getTotalCount() % rows;
			int pageIndex = (int) Math.ceil(this.getTotalCount() / (double) rows);
			startRow = this.getCurrCount() > 0 ? 0 : pageSize * ((page - 1) - pageIndex) + (m != 0 ? pageSize - m : 0);
		}
		return startRow;
	}

	// public void setStartRow(Integer startRow) {
	// this.startRow = startRow;
	// }
}
